<?php

include "../../../lib/start.php";

check_session();
check_permission(DOC_PERM);

if($_REQUEST['data'] == date("Y-m-d"))
	header("Location: today.php");

$sel_alunni = "SELECT id_alunno, cognome, nome FROM alunni WHERE alunni.id_classe = ".$_SESSION['__classe__']->get_ID()." ORDER BY cognome, nome";
$res_alunni = $db->execute($sel_alunni);

$sel_registro = "SELECT id_reg, ingresso, uscita, data FROM reg_classi WHERE id_classe = ".$_SESSION['__classe__']->get_ID()." AND id_anno = ".$_SESSION['__current_year__']->get_ID()." AND data = '".$_REQUEST['data']."'";
//print $sel_registro;
$res_registro = $db->execute($sel_registro);
$_SESSION['registro'] = $res_registro->fetch_assoc();

if(date("N", strtotime($_REQUEST['data'])) == 1)
	$data_back = date("Y-m-d", strtotime($_REQUEST['data']." -2 days"));
else
	$data_back = date("Y-m-d", strtotime($_REQUEST['data']." -1 days"));
if(date("N", strtotime($_REQUEST['data'])) == 6)
	$data_forward = date("Y-m-d", strtotime($_REQUEST['data']." +2 days"));
else
	$data_forward = date("Y-m-d", strtotime($_REQUEST['data']." +1 days"));
	
while(in_array($data_back, $holydays) || (date("N", strtotime($data_back)) == 7)){
	$data_back = date("Y-m-d", strtotime($data_back." -1 days"));
}
while(in_array($data_forward, $holydays) || (date("N", strtotime($data_forward)) == 7)){
	$data_forward = date("Y-m-d", strtotime($data_forward." +1 days"));
}

include "registro_classe.html.php";

?>